#include "ScnsGt911.c.h"

#if defined(SCNS_GT911_ENABLE)&&SCNS_GT911_ENABLE==1

#include "ScnsIic.h"
#include "ScnsPcf8574.h"

#if !(defined(SCNS_IIC_ENABLE)&&SCNS_IIC_ENABLE==1)

#include "i2c.h"

#endif

const ScnsBspGt911Config scnsBspGt911Config[SCNS_GT911_MAX]={
    {.swap=1,.xa=0,.ya=480/*+160*/,.xb=1,.yb=-1},
};

ScnsStatus scnsBspGt911Init(ScnsGt911Enum gt9N)
{

    return SCNS_STATUS_OK;
}

ScnsStatus scnsBspGt911Write(ScnsGt911Enum gt9N,const uint8*addr,uint8 addrLen,const uint8*data,uint8 dataLen)
{
#if defined(SCNS_IIC_ENABLE)&&SCNS_IIC_ENABLE==1
    return scnsIicWriteTick(SCNS_IIC_SOFT_1,0XBA,addr,addrLen,data,dataLen,8);
#else
    const uint16 ADDR=(addr[0]<<8)|addr[1];
    HAL_I2C_Mem_Write(&hi2c1,0XBA,ADDR,2,data,dataLen,0XFFFFFF);
    return SCNS_STATUS_OK;
#endif
}

ScnsStatus scnsBspGt911Read(ScnsGt911Enum gt9N,const uint8*addr,uint8 addrLen,uint8*data,uint8 dataLen)
{
#if defined(SCNS_IIC_ENABLE)&&SCNS_IIC_ENABLE==1
    return scnsIicReadTick(SCNS_IIC_SOFT_1,0XBA,addr,addrLen,data,dataLen,8);
#else
    const uint16 ADDR=(addr[0]<<8)|addr[1];
    HAL_I2C_Mem_Read(&hi2c1,0XBA,ADDR,2,data,dataLen,0XFFFFFF);
    return SCNS_STATUS_OK;
#endif
}

void scnsBspGt911SetInt(ScnsGt911Enum gt9N,uint8 dat)
{
    scnsPcf8574WriteBit(SCNS_PCF8574_1,0,dat);
}

void scnsBspGt911SetIntDir(ScnsGt911Enum gt9N,uint8 in)
{
    if(in)
    {
        scnsPcf8574WriteBit(SCNS_PCF8574_1,0,1);
    }
}

uint8 scnsBspGt911GetInt(ScnsGt911Enum gt9N)
{
    return scnsPcf8574ReadBit(SCNS_PCF8574_1,0);
}

#endif
